package cn.nuc.edu.onlinestore.util;

/**
 * 分页控制对象
 * 
 * @author 王凯
 */
public class PageControl {
	/**
	 * 当前第几页
	 */
	private Integer currentindex;
	
	/**
	 * 每页多少行数据(默认每页10行数据)
	 */
	private Integer pagesize = 10;
	
	/**
	 * 总记录数
	 */
	private Integer rscount;

	/**
	 * 总页数
	 */
	private Integer pagecount;
	
	/**
	 * 分页控件一次显示多少页(默认一次5页)
	 */
	private Integer showpcount = 5;
	
	/**
	 * 当前分页控件显示的最大页数
	 */
	private Integer maxpage;

	/**
	 * 当前分页控件显示的最小页数
	 */
	private Integer minpage;

	public Integer getCurrentindex() {
		return currentindex;
	}

	public void setCurrentindex(Integer currentindex) {
		this.currentindex = currentindex;
	}

	public Integer getPagesize() {
		return pagesize;
	}

	public void setPagesize(Integer pagesize) {
		this.pagesize = pagesize;
	}

	public Integer getRscount() {
		return rscount;
	}

	public void setRscount(Integer rscount) {
		this.rscount = rscount;
		dealpage();
	}

	public Integer getPagecount() {
		return pagecount;
	}

	public void setPagecount(Integer pagecount) {
		this.pagecount = pagecount;
	}

	public Integer getShowpcount() {
		return showpcount;
	}

	public void setShowpcount(Integer showpcount) {
		this.showpcount = showpcount;
	}

	public Integer getMaxpage() {
		return maxpage;
	}

	public void setMaxpage(Integer maxpage) {
		this.maxpage = maxpage;
	}

	public Integer getMinpage() {
		return minpage;
	}

	public void setMinpage(Integer minpage) {
		this.minpage = minpage;
	}
	
	private void dealpage(){
		//获取总页数
		pagecount = rscount / pagesize;
		if(rscount % pagesize > 0){
			pagecount++;
		}
		
		//计算最大(最小)显示页数
		maxpage = 0;//当前显示最大页码
		minpage = 0;
		if(pagecount <= showpcount){//当总页数小于等于显示的页数时
			maxpage = pagecount;
			minpage = 1;
		}else{
			Integer buff = showpcount / 2; //取中间数。maxpage=index+buff
			buff = currentindex + buff;
			if(buff <= showpcount){
				maxpage = showpcount;
				minpage = 1;
			}else if(buff<pagecount){
				maxpage = buff;
				minpage = maxpage - showpcount + 1;
				
			}else if(buff>=pagecount){
				maxpage = pagecount;
				minpage = maxpage - showpcount + 1;
			}
		}
	}
}
